//复制进去哈，假如你自己写的话，最好也看看这个模板，有些地方要注意
#include <rtthread.h>
#include <rtdevice.h>
#include <lvgl.h>
#include <rtdbg.h>
#include "drv_touch_xpt2406.h"


//static lv_obj_t * label;
//
//static void slider_event_cb(lv_event_t * e)
//{
//    lv_obj_t * slider = lv_event_get_target(e);
//
//    /*Refresh the text*/
//    lv_label_set_text_fmt(label, "%"LV_PRId32, lv_slider_get_value(slider));
//    lv_obj_align_to(label, slider, LV_ALIGN_OUT_TOP_MID, 0, -15);    /*Align top of the slider*/
//}
//
//void test_lvgl_tabviwe()
//{
//    lv_obj_t * slider = lv_slider_create(lv_scr_act());
//       lv_obj_set_width(slider, 100);                          /*Set the width*/
//       lv_obj_center(slider);                                  /*Align to the center of the parent (screen)*/
//       lv_obj_add_event_cb(slider, slider_event_cb, LV_EVENT_VALUE_CHANGED, NULL);     /*Assign an event function*/
//
//       /*Create a label below the slider*/
//       label = lv_label_create(lv_scr_act());
//       lv_label_set_text(label, "0");
//       lv_obj_align_to(label, slider, LV_ALIGN_OUT_TOP_MID, 0, -15);    /*Align top of the slider*/
//
// }



static void event_handler(lv_event_t * e)
{
    lv_event_code_t code = lv_event_get_code(e);

    if(code == LV_EVENT_CLICKED) {
        LV_LOG_USER("Clicked");
    }
    else if(code == LV_EVENT_VALUE_CHANGED) {
        LV_LOG_USER("Toggled");
    }
}

void lv_example_btn_1(void)
{
    lv_obj_t * label;

    lv_obj_t * btn1 = lv_btn_create(lv_scr_act());
    lv_obj_add_event_cb(btn1, event_handler, LV_EVENT_ALL, NULL);
    lv_obj_align(btn1, LV_ALIGN_CENTER, 0, -40);

    label = lv_label_create(btn1);
    lv_label_set_text(label, "Button");
    lv_obj_center(label);

    lv_obj_t * btn2 = lv_btn_create(lv_scr_act());
    lv_obj_add_event_cb(btn2, event_handler, LV_EVENT_ALL, NULL);
    lv_obj_align(btn2, LV_ALIGN_CENTER, 0, 40);
    lv_obj_add_flag(btn2, LV_OBJ_FLAG_CHECKABLE);
    lv_obj_set_height(btn2, LV_SIZE_CONTENT);

    label = lv_label_create(btn2);
    lv_label_set_text(label, "Toggle");
    lv_obj_center(label);
}


void lv_user_gui_init(void)
{
    rt_kprintf("%s\n",__FUNCTION__);
    lv_example_btn_1();
}

//static void lvgl_demo_run(void *p)
//{
//    rt_kprintf("%s\n",__FUNCTION__);
//    rt_thread_mdelay(500);
//
//    //test_lvgl_tabviwe();
//}
//
//int rt_lvgl_demo_init(void)
//{
//    rt_err_t ret = RT_EOK;
//    rt_thread_t thread = RT_NULL;
//
//    rt_kprintf("%s\n",__FUNCTION__);
//    /* init littlevGL */
//    //lv_init();
//
//    /* littleGL demo gui thread */
//    thread = rt_thread_create("lv_demo", lvgl_demo_run, RT_NULL, 4*1024, 5, 10);
//    if(thread == RT_NULL)
//    {
//        return RT_ERROR;
//    }
//    rt_thread_startup(thread);
//
//    return ret;
//}
//INIT_APP_EXPORT(rt_lvgl_demo_init);

